const express = require('express')
const app = express()
const Mock = require('mockjs')
app.use(express.static('static'))
app.all('*', (req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*')
    next()
})
//search-info_index页面
app.get('/ctg/infos', (req, res) => {
    let result = {
        'data': [
            { 'search_infos': '@cword(2, 4)' },
            { 'search_infos': '@cword(2, 4)' },
            { 'search_infos': '@cword(2, 4)' },
            { 'search_infos': '@cword(2, 4)' },
            { 'search_infos': '@cword(2, 4)' },
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
})
//search-info2_index页面
app.get('/ctg/info', (req, res) => {
    let result = {
        'data': [
            { 'search_info': '@cword(2, 5)' },
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
})
//商品信息栏_index页面
app.get('/ctg/list', (req, res) => {
    let result = {
        'data': [
            {
                id: '@id',
                imgsrc: '/static/ctg/1.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/2.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/3.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/4.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/5.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/6.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/7.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/8.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/9.png',
                title: '@ctitle(4)'
            },
            {
                id: '@id',
                imgsrc: '/static/ctg/10.png',
                title: '@ctitle(4)'
            },
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
}),
    app.get('/ctg/goodsLists', (req, res) => {
        let result = {
            'data': [
                {
                    id: '@id',
                    atitle: '@cword(4)',
                    btitle: '@ctitle(5)',
                    imgsrc: '/static/p_11.jpg',

                },
                {
                    id: '@id',
                    atitle: '@cword(4)',
                    btitle: '@ctitle(5)',
                    imgsrc: '/static/p_22.png',
                },
                {
                    id: '@id',
                    atitle: '@cword(4)',
                    btitle: '@ctitle(5)',
                    imgsrc: '/static/p_33.png',
                },
                {
                    id: '@id',
                    atitle: '@cword(4)',
                    btitle: '@ctitle(5)',
                    imgsrc: '/static/p_44.png',
                }
            ]
        }
        res.send({
            error: 0,
            message: 'it is ok',
            data: Mock.mock(result).data
        })
    })
//限时秒杀_index页面
app.get('/ctg/deLists', (req, res) => {
    let result = {
        'data': [
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de1.jpg',

            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de2.png',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de7.jpg',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de4.jpg',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de10.jpg',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de6.jpg',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de3.jpg',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de8.jpg',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de9.jpg',
            },
            {
                id: '@id',
                desc: '@cword(8,10)',
                'bprice|2-300.1-2': 1,
                'aprice|2-300.1-2': 1,
                imgsrc: '/static/de5.jpg',
            },
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
})
//shoplist_index页面
app.get('/ctg/shoplists', (req, res) => {
    let result = {
        'data|10': [
            {
                id: '@id',
                imgsrc: '/static/s1.jpg',
                title: '@ctitle(6,10)',
                'dnum|10-30': 0,
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
            },
            {
                id: '@id',
                imgsrc: '/static/s2.jpg',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s3.jpg',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s4.png',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s5.jpg',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s6.png',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s7.jpg',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s8.jpg',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s9.jpg',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },
            {
                id: '@id',
                imgsrc: '/static/s10.jpg',
                title: '@ctitle(6,10)',
                'star|1-5': '⭐',
                'yhqq|1-2': [
                    { title: '@ctitle(10,15)', 'type': '领券' },
                ],
                'yhq|0-9': [
                    { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
                ],
                'star_score|1-5.1': 0,
                'salesum|400-1000': 0,
                'ms|1-5': 1,
                'md|1-5': 1,
                'dm|10-30': 1,
                'dd|100-3000': 1,
                'dnum|10-30': 0,
            },

        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
})
//userlist_user页面
app.get('/user/list', (req, res) => {
    let result = {
        'data': [
            {
                'username': '@word(8,16)',
                'usernum': /^1[385][1-9]\*\*\*\*[1-9]\d{3}/,
                'nums|1-20': 1,
                'numd|0-3000': 1,
                'numc|1-10': 1,
            }
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
})
//list_shop页面
app.get('/shop/menus', (req, res) => {
    let result = {
        'data|10-30': [
            {
                id: '@id',
                text: '@cword(2,4)',
                'children|2-10': [
                    {
                        id: '@id',
                        text: '@cword(2,4)'
                    }
                ]
            }
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
})
///products_list_shop页面
app.get('/shop/products', (req, res) => {
    let result = {
        'data|6-10': [
            {
                id: '@id',
                title: '@ctitle(10,15)',
                'price|2-300.1-2': 1,
                'store|1-10': 0,
                'pnum|1-100': 0,
                'elnum|90-100': 0,
                num: 0,
                imgsrc: '/static/order/o' + '@natural(1,26)' + '.jpeg' 
            }
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data
    })
})
///products_list_shop页面
app.get('/shop/shoplist', (req, res) => {
    let result = {
        'data': [{
            id: '@id',
            'yhqq|1-2': [
                { title: '@ctitle(10,15)', 'type': '领券' },
            ],
            'yhq|1-2': [
                { title: '@ctitle(10,15)', 'type|1': ['满减', '折扣', '打包'] }
            ],
            'dm|10-60': 1,
            'title|6-10': 1,
            'dnum|4-20': 0,
            'transform': '@cword(2, 4)',
            'img': [
                { imgsrc: '/static/s1.jpg' },
            ],
        }],
        'data2|2-10': [
            {
                id: '@id',
                'cnum|10-60': 1,
                'cmoney|100-300': 1,
                'c_limit|1': [
                    '限到家使用', '仅限购买品牌指定产品', '仅限南京地区指定产品',
                ],
                'c_date|1': [
                    '领取后当日有效', '领取三天后使用', '领取后隔天使用',
                ]
            }
        ],
        'data3': [{
            imgsrc: '/static/evaluateHeader.jpg',
            'grade|1-5.1': 0,
            'star|1-5': '⭐',
            'synthesis|10-500': 0,
            'username': '@cword(4, 8)',
            'date': '@datetime()',
            'benefits': '日期新,分量足,商品新鲜,质量优,口味佳'

        }],
        'data4': [{
            'snum|100-2000': 0,
            'salenum|1-9': 0,
            'peoplenum|100-2000': 0,
            'mtime': '@time("HH:mm:00")',
            'etime': '@time("HH:mm:00")',
            'position': '@cword(6,10)',
            'phone': /^0\d{3}-\d{8}?$/
        }]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data,
        data2: Mock.mock(result).data2,
        data3: Mock.mock(result).data3,
        data4: Mock.mock(result).data4
    })
})
//orderlist页面
app.get('/shop/orderlist', (req, res) => {
    let result = {
        'data|1-3': [{
            'shoptitle': '@cword(4,6)',
            'shoplocation': '@county()',
            'shopstatus|1': ['已完成', '已退款'],
            'dtime': '@date("MM-dd")',
            'htime': '@date("HH-mm")',
            'price|2-300.1-2': 1,
            'sum|6-10': 1,
            'transform|1': ['达达专送', '菜鸟专送', '贝壳外卖', '即刻到家'],
            'img|4': [
                { imgsrc: '/static/order/o' + '@natural(1,15)' + '.jpeg' }
            ],
        }]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data,
    })
})
  //shopcar页面
  app.get('/shop/shopcar', (req, res) => {
    let result = {
        'data|1-3': [{
            'id':'@id()',
            'shopname': '@cword(4,6)',
            'location': '@county()',
            'shopstatus|1': ['无货', '有货'],
            'img|5': [
                { imgsrc: '/static/order/o' + '@natural(1,18)' + '.jpeg' ,
                'price|1-40.1-2': 1}
            ]
        }],
        'data3':[{
            'id':'@id()',
            'position':'@cword(6,10)',
        }],
        'data2|1-2': [{
            'id':'@id()',
            'shopname': '@cword(4,6)',
            'location': '@county()',
            'shopstatus|1': ['无货', '有货'],
            'img|5': [
                { imgsrc: '/static/order/o' + '@natural(1,18)' + '.jpeg' ,
                'price|1-40.1-2': 1}
            ]
        }],

    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data,
        data2: Mock.mock(result).data2,
        data3: Mock.mock(result).data3,
    })
})  
///goods_list_shop页面
app.get('/goods/products', (req, res) => {
    let result = {
        'data1':[{
            title: '@ctitle(10,15)',
            'discount':'@cword(10,15)',
            'oldprice|2-15.1-2': 1,
            'nowprice|16-30.1-2':1,
            'shopname': '@cword(6,8)',
        }],
        'data2|6': [
            {
                id: '@id',
                title: '@ctitle(10,15)',
                'price|2-300.1-2': 1,
                num: 0,
                imgsrc: '/static/order/o' + '@natural(1,26)' + '.jpeg' 
            }
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data1: Mock.mock(result).data1,
        data2: Mock.mock(result).data2
    })
})
// homeCategorySearch页面search
app.get('/shop/shopSearch',(req,res)=>{
    let result={
        'data|10':[
            {
                id:'@id',
                searchitems:'@cword(2,4)'
            }
        ]
    }
    res.send({
        error: 0,
        message: 'it is ok',
        data: Mock.mock(result).data,
    })
})
// 列表页
app.get('/shop/shopproduct',(req,res)=>{
    let result={
        'data1|8-12': [
            {
                id: '@id',
                text: '@cword(2,4)',
            }
        ],
        'data2|2-6':[
                {text: '@cword(2,4)',
                'son|2-10': [{
                         id: '@id',
                         imgsrc: '/static/order/o' + '@natural(1,26)' + '.jpeg' ,
                         title: '@ctitle(2,4)',
                }]
            }]
     }
    res.send({
        error: 0,
        message: 'it is ok',
        data1: Mock.mock(result).data1,
        data2: Mock.mock(result).data2,
    })
})
app.listen(8088);

